﻿using System.Collections.Generic;
using Microsoft.Practices.Unity;
using System.Linq;
using BaseTypesLib.Model;
using BBInterfaceNET.CommonServices;

namespace BBInterfaceNET.Toolbox.Services
{
    public class ToolboxService:IToolboxService
    {
        IUnityContainer container;
        public ToolboxService(IUnityContainer container)
        {
            this.container = container;
        }
        public List<ToolboxItem> GetItems()
        {
            var fields = container.ResolveAll<Field>();

            return fields.Where(p=>p.GetType().IsAbstract==false).Select(p => new ToolboxItem
            {
                Description = p.GetType().Name,
                Type = p.GetType(),
                Category = GetCategory(p)
            }).ToList();
        }
        private string GetCategory(Field field)
        {
            if (field is Manager)
                return "Managers";
            else
                return "Fields";
        }
    }
}
